﻿Public Class frmMeetingsSearch

    Dim strNameForm As String = "Search Meeting"
    Public strSqlWhere As String = " 1=1 "

    Public Function Initialize() As Boolean
        Try
            Me.Text = strNameForm

            cboTopics.Load("Select * From Topics", "Name", gConnectionStringAgenda.ToString)
            cboUS.Load("Select * From UserStories", "Name", gConnectionStringAgenda.ToString)
            Dim listStatus As New List(Of Base.GlobalConst)
            listStatus.Add(MEETING_STATUS_PLANNED)
            listStatus.Add(MEETING_STATUS_DONE)
            listStatus.Add(MEETING_STATUS_CANCELLED)
            cboStatus.DataSource = listStatus
            cboStatus.ValueMember = "NUMBER"
            cboStatus.DisplayMember = "NAME"
            listStatus = Nothing
            cboStatus.SelectedIndex = -1

            AddHandler cboTopics.OnInsert, AddressOf InterfaceManager.Topics_OnInsert
            AddHandler cboTopics.OnModify, AddressOf InterfaceManager.Topics_OnModify
            AddHandler cboUS.OnInsert, AddressOf InterfaceManager.UserStories_OnInsert
            AddHandler cboUS.OnModify, AddressOf InterfaceManager.UserStories_OnModify

            Return True
        Catch ex As Exception
            Base.ShowError.Show("Initialize", Me.Name, "Initialize", ex)
            Return False
        End Try
    End Function

#Region "Commands"

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Try
            If txtName.Text <> "" Then strSqlWhere &= String.Format(" and Name like '{0}%'", txtName.Text)
            If txtDescription.Text <> "" Then strSqlWhere &= String.Format(" and Description like '{0}%'", txtDescription.Text)
            If txtDate.Text <> "" Then strSqlWhere &= String.Format(" and Date ='{0}'", txtDate.DataMySql)
            If txtTime.Text <> "" Then strSqlWhere &= String.Format(" and Time ='{0}'", txtTime.Time)
            If cboTopics.SelectedIndex <> -1 Then strSqlWhere &= String.Format(" and TopicsID={0}", cboTopics.SelectedValue)
            If cboUS.SelectedIndex <> -1 Then strSqlWhere &= String.Format(" and UserStoriesID={0}", cboUS.SelectedValue)
            If cboStatus.SelectedIndex <> -1 Then strSqlWhere &= String.Format(" and Status={0}", cboStatus.SelectedValue)


            Me.DialogResult = DialogResult.OK
        Catch ex As Exception
            Base.ShowError.Show("Search", Me.Name, "cmdSearch_Click", ex)
        End Try
    End Sub

#End Region

#Region "Form events"

    Private Sub Me_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then
            Me.DialogResult = DialogResult.Cancel
        End If
    End Sub

#End Region

End Class